<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:p="http://primefaces.org/ui" >

	<h:form id="frm1">
		<p:growl id="msgs1" showDetail="true"/>
		<p:panel id="biPanel" style="margin-bottom:5px">
			<h:panelGrid columns="3" cellspacing="10">
				<p:commandButton  value="保存开票单" icon="ui-icon-check" action="#{invInfoMB.saveAction}" update=":frm1:Inv_id :frm1:msgs1"/>
				<p:commandButton  value="新增开票单" icon="ui-icon-pencil" action="#{invInfoMB.commitAction}" update=":frm1 :frm1:rdt"/>
			</h:panelGrid>
			
			<h:panelGrid columns="8" cellspacing="10">
				<p:outputLabel value="开票编号：" />
				<p:inputText  id="Inv_id" value="#{invInfoMB.io.invId}" required="true" requiredMessage="开票编号必须输入"/>
				<p:outputLabel value="开票金额：" />
				<p:inputText  id="Inv_amount" value="#{invInfoMB.io.amount}" required="false" requiredMessage="开票金额必须输入" 
				readonly="true" disabled="true"/>
				<p:outputLabel value="开票日期：" />
				<p:calendar locale="zh" navigator="true"  value="#{invInfoMB.io.invDate}" 
					pattern="yyyy-MM-dd" mask="true"  mode="popup"	showOn="button" popupIconOnly="true"
					required="false" requiredMessage="开票日期必须输入" />
				<p:outputLabel value="状态：" />
				<p:selectOneMenu value="#{invInfoMB.io.status}" effect="fold" style="width:80%;" 
					required="true" requiredMessage="开票状态必须输入" disabled="true">
					<f:selectItem itemLabel="请选择..." itemValue=""/>
					<f:selectItems value="#{invInfoMB.itemsInvInfoStatus}" />
				</p:selectOneMenu>
				
				<p:outputLabel value="合同ID" />
				<p:selectOneMenu value="#{invInfoMB.selectedContract}" converter="bmeContractConverter" 
						effect="fade"  style="width:80%" panelStyle="width:180px" 
                        var="t" filter="true" filterMatchMode="startsWith"
                        required="true" requiredMessage="合同名称必须输入" >
                    <p:ajax listener="#{invInfoMB.onSelectedContract}" update=":frm1:Inv_contName :frm1:Inv_custName" /> 
                    <f:selectItem itemLabel="请选择..." itemValue=""/>    
		            <f:selectItems value="#{invInfoMB.bmeContracts}" var="scontrtacr" itemLabel="#{scontrtacr.id}" itemValue="#{scontrtacr}" />
		 
		            <p:column style="width:10%">
		                <h:outputText value="#{t.id}" />
		            </p:column>		 
		            <p:column>
		                <h:outputText value="#{t.name}" />
		            </p:column>        
		        </p:selectOneMenu>
				<p:outputLabel value="合同名称：" />
				<p:inputText  id="Inv_contName" value="#{invInfoMB.selectedContract.name}" readonly="true" disabled="true"/>
				<p:outputLabel value="客户：" />
				<p:inputText  id="Inv_custName" value="#{invInfoMB.selectedContract.custName}" readonly="true" disabled="true"/>
			</h:panelGrid>
			
			
			<h:panelGrid id="detailGrid" columns="10" cellspacing="10" >					
				<p:commandButton id="detailBtn" value="选择请款单..."  type="button" icon="fa fa-fw fa-search-plus" onclick="PF('ovpl2').loadContents();" />
			</h:panelGrid>
			<!-- 选择请款单 -->
		    <p:overlayPanel id="ovDetailPanel" for="detailBtn" hideEffect="fade" dynamic="true" 
		   				showCloseIcon="false" style="width:800px"  widgetVar="ovpl2"  >
		        <p:dataTable var="srow" value="#{invInfoMB.vod}"  
		        	paginator="true" paginatorPosition="bottom" emptyMessage="没有记录"
		         	rowKey="#{srow.id}"  selection="#{invInfoMB.selectedVod}" >
		         	
					<p:column selectionMode="multiple" style="width:16px;text-align:center"/>
		           <p:column headerText="请款编号">
		               <h:outputText value="#{srow.id}" />
		           </p:column>
		           <p:column headerText="请款日期">
		               <h:outputText value="#{srow.reqDate}" />
		           </p:column>
		           <p:column headerText="合同编号">
		               <h:outputText value="#{srow.bmeContract.id}" />
		           </p:column>
		           <p:column headerText="合同名称">
		               <h:outputText value="#{srow.bmeContract.name}" />
		           </p:column>
		       </p:dataTable>
			   <h:panelGrid columns="3" cellspacing="10">					  
					<p:commandButton value="确认"	icon="ui-icon-check"  oncomplete="PF('ovpl2').hide();" 
						action="#{invInfoMB.selectPayroll}" update=":frm1">
					</p:commandButton>	
				</h:panelGrid>
		    </p:overlayPanel>
			
			<p:dataTable id="rdt" value="#{invInfoMB.selectedRtn}"  var="row"  rowIndexVar="rowNum"
				resizableColumns="true" liveResize="true" 
				editable="true"  style="margin-bottom:5px"
				paginator="true" paginatorPosition="bottom" rows="8" 
                rowsPerPageTemplate="5,10,15"  emptyMessage="没有记录" rowKey="#{row.id}" >
				
				<f:facet name="header">请款单信息</f:facet>
    
				<p:ajax event="rowEdit" listener="#{invInfoMB.onRowEdit}"
					update=":frm1:msgs1 :frm1:Inv_amount" />
				<p:ajax event="rowEditCancel"	listener="#{invInfoMB.onRowCancel}"
					update=":frm1:msgs1" />
				<p:column headerText="No." style="width:5%">
					#{rowNum+1}
				</p:column>
				<p:column headerText="请款编号" sortBy="#{row.bmePayroll.id}">
					<p:cellEditor>
						<f:facet name="output">
							<h:outputText value="#{row.bmePayroll.id}" />
						</f:facet>
						<f:facet name="input">
							<h:outputText value="#{row.bmePayroll.id}" />
						</f:facet>
					</p:cellEditor>
				</p:column>
				<p:column headerText="请款总额">
					<p:cellEditor>
						<f:facet name="output">
							<h:outputText value="#{row.payAmount}" />
						</f:facet>
						<f:facet name="input">
							<h:outputText value="#{row.payAmount}"/>
						</f:facet>
					</p:cellEditor>
				</p:column>
				<p:column headerText="开票金额">
					<p:cellEditor>
						<f:facet name="output">
							<h:outputText value="#{row.invAmount}" />
						</f:facet>
						<f:facet name="input">
							<p:inputText value="#{row.invAmount}" style="width:100%"
								label="开票金额" />
						</f:facet>
					</p:cellEditor>
				</p:column>
				<p:column headerText="开票比例（百分比）">
					<p:cellEditor>
						<f:facet name="output">
							<h:outputText value="#{row.invPercent}" />
						</f:facet>
						<f:facet name="input">
							<p:inputText value="#{row.invPercent}" style="width:100%"
								label="开票比例（百分比）" />
						</f:facet>
					</p:cellEditor>
				</p:column>
				<p:column headerText="备注">
					<p:cellEditor>
						<f:facet name="output">
							<h:outputText value="#{row.remarks}" />
						</f:facet>
						<f:facet name="input">
							<p:inputText value="#{row.remarks}" style="width:100%"
								label="备注" />
						</f:facet>
					</p:cellEditor>
				</p:column>
				<p:column headerText="修改" style="width:32px">
					<p:rowEditor editTitle="修改" cancelTitle="取消" saveTitle="保存"/>
				</p:column>
				<p:column headerText="删除" style="width:32px">
					<p:commandButton icon="ui-icon-minus"   title="删除"  immediate="true"
						action="#{invInfoMB.delPayroll}" update=":frm1">
						<f:setPropertyActionListener value="#{row}"
							target="#{invInfoMB.selected}" />
						<p:confirm header="确认" message="你确定删除此产品信息？" icon="ui-icon-alert" />
					</p:commandButton>
						
				</p:column>				
			</p:dataTable>
    
		</p:panel>		
	</h:form>
	
	<!-- confirm to del product -->
    <p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
        <p:commandButton value="确认" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
        <p:commandButton value="取消" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
    </p:confirmDialog>
</ui:composition>
